//! Copyright 2012 NTH Technology, Inc.
//! All rights reserved
//!
#ifndef __BoardHardware_h__
#define __BoardHardware_h__

// #define BOARD_V1
#define BOARD_V2

#if defined ( BOARD_V1 )

#elif defined ( BOARD_V2 )
    //--------------------------------------------------------------
    // define LED
    #define LED_PERIPH          RCC_APB2Periph_GPIOA
    #define LED_PORT            GPIOA
    #define LED_PIN             GPIO_Pin_2
    #define DEBUG_LED_OFF       GPIOA->BRR = (1<<2)
    #define DEBUG_LED_ON        GPIOA->BSRR  = (1<<2)
    #define DEBUG_LED_INV       if ((GPIOA->IDR & (1<<2))!=0) DEBUG_LED_OFF; else DEBUG_LED_ON

    //--------------------------------------------------------------
    // khai bao chan SPI1 ket noi voi ENC28J60
    #define ENC28J60_SPI                       SPI1
    #define ENC28J60_SPI_CLK                   RCC_APB2Periph_SPI1

    #define ENC28J60_SPI_SCK_PIN               GPIO_Pin_5                   /* PA.5 */
    #define ENC28J60_SPI_SCK_GPIO_PORT         GPIOA                        /* GPIOA */
    #define ENC28J60_SPI_SCK_GPIO_CLK          RCC_APB2Periph_GPIOA
    #define ENC28J60_SPI_SCK_LOW               ENC28J60_SPI_SCK_GPIO_PORT->BRR = (1<<5)
    #define ENC28J60_SPI_SCK_HIGH              ENC28J60_SPI_SCK_GPIO_PORT->BSRR = (1<<5)

    #define ENC28J60_SPI_MISO_PIN              GPIO_Pin_6                   /* PA.6 */
    #define ENC28J60_SPI_MISO_GPIO_PORT        GPIOA                        /* GPIOA */
    #define ENC28J60_SPI_MISO_GPIO_CLK         RCC_APB2Periph_GPIOA
    #define ENC28J60_SPI_MISO_LOW              ENC28J60_SPI_MISO_GPIO_PORT->BRR = (1<<6)
    #define ENC28J60_SPI_MISO_HIGH             ENC28J60_SPI_MISO_GPIO_PORT->BSRR = (1<<6)

    #define ENC28J60_SPI_MOSI_PIN              GPIO_Pin_7                   /* PA.7 */
    #define ENC28J60_SPI_MOSI_GPIO_PORT        GPIOA                        /* GPIOA */
    #define ENC28J60_SPI_MOSI_GPIO_CLK         RCC_APB2Periph_GPIOA
    #define ENC28J60_SPI_MOSI_LOW              ENC28J60_SPI_MOSI_GPIO_PORT->BRR = (1<<7)
    #define ENC28J60_SPI_MOSI_HIGH             ENC28J60_SPI_MOSI_GPIO_PORT->BSRR = (1<<7)

    #define ENC28J60_CS_PIN                    GPIO_Pin_0                   /* PB.0 */
    #define ENC28J60_CS_GPIO_PORT              GPIOB                        /* GPIOB */
    #define ENC28J60_CS_GPIO_CLK               RCC_APB2Periph_GPIOB
    #define ENC28J60_CS_LOW                    ENC28J60_CS_GPIO_PORT->BRR = (1<<0)
    #define ENC28J60_CS_HIGH                   ENC28J60_CS_GPIO_PORT->BSRR = (1<<0)

    #define ENC28J60_RST_PIN                    GPIO_Pin_1                   /* PB.1 */
    #define ENC28J60_RST_GPIO_PORT              GPIOB                        /* GPIOB */
    #define ENC28J60_RST_GPIO_CLK               RCC_APB2Periph_GPIOB
    #define ENC28J60_RST_LOW                    ENC28J60_RST_GPIO_PORT->BRR = (1<<1)
    #define ENC28J60_RST_HIGH                   ENC28J60_RST_GPIO_PORT->BSRR = (1<<1)

    #define ENC28J60_INT_PIN                    GPIO_Pin_3                   /* PA.3 */
    #define ENC28J60_INT_GPIO_PORT              GPIOA                        /* GPIOA */
    #define ENC28J60_INT_GPIO_CLK               RCC_APB2Periph_GPIOA
    #define ENC28J60_INT_INPUT                  (((ENC28J60_INT_GPIO_PORT->IDR)>>3)&0x01)

#endif


#endif  // __BoardHardware_h__

